//
//  ZBBaseRequest.h
//  ZBDay
//
//  Created by xzb on 2018/2/7.
//  Copyright © 2018年 xzb. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "ZBNetworkManager.h"

typedef NS_ENUM(NSInteger, ZBRequestPriority) {
    ZB_REQ_PRIORITY_LOW = 0, // 低优先级，请求错误不提示
    ZB_REQ_PRIORITY_NORMAL,  // 普通优先级，请求错误用hud提示
    ZB_REQ_PRIORITY_HIGH,    // 高优先级，请求错误弹框提示
};

@interface ZBBaseRequest : NSObject

/**
 * 请求优先级
 */
@property (nonatomic, assign) ZBRequestPriority priority;
/**
 * 请求方法
 */
@property (nonatomic, copy) NSString *method;
/**
 * 返回 modelName
 */
@property (nonatomic, copy) NSString *modelName;
/**
 * 禁止自动转换模型, 默认是NO, 设置为YES会禁止转化
 */
@property (nonatomic, assign) BOOL disableAutoModelize;
/**
 * 请求参数
 */
@property (nonatomic, retain) NSMutableDictionary *fields;

/**
 * api url
 */
@property (nonatomic, copy) NSString *apiUrl;

/*
 * 是否缓存
 */
@property (nonatomic, assign, readonly) BOOL shouldCache;

/**
 * POST/GET
 */
@property (nonatomic, copy) NSString *httpType;

/**
 请求头
 */
@property (nonatomic, strong) NSDictionary *headers;
/**
 * 是否正在请求中
 */
@property (nonatomic, assign) BOOL isExecuting;

/**
 * 请求完成回调
 */
@property (nonatomic, copy) onZBCompletionBlock onCompletion;

/**
 * 执行请求时，如果本地有缓存，而且有onLoadFromCache，则替而代之执行这个，等网络回来之后，再执行onCompletion
 */
@property (nonatomic, copy) onLoadFromCacheBlock onLoadFromCache;
/**
 * 错误回调
 */
@property (nonatomic, copy) onZBErrorBlock onError;
/**
 *  带HUD
 */
@property (nonatomic, assign) BOOL showHUD;

+ (instancetype)request;

/**
 * 发送请求
 */
- (void)sendQuery;
/**
 * 取消请求
 */
- (void)cancelRequest;
/**
 * 设置api的版本
 */
@property (nonatomic, copy) NSString *apiVersion;

/// 重写这个方法,可以把response转成你想要的数据格式;
- (id)resultWithResponse:(NSDictionary *)responseDictionary;

///重写这个方法,自定义回调结果;已经在主线程
- (void)handleSuccessResult:(id)result;

///重写这个方法,自定义缓存回调
- (void)handleCacheResult:(id)result;

@end
@interface ZBBaseRequest (Subscript)

- (id)objectForKeyedSubscript:(id)key; //getter

- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; //setter

@end




